package com.winchain.provider.expiration.rx;

import com.shell.framework.command.ChainBase;
import com.shell.framework.command.CommandContext;
import com.shell.framework.rx.OnErrorNotImplementedSubscriber;
import com.winchain.chainbill.bill.base.po.CbRec;
import com.winchain.chainbill.bill.biz.Bill;
import com.winchain.chainbill.bill.biz.send.cmd.BillMoveCmd;
import com.winchain.chainbill.bill.biz.send.cmd.BillOptCmd;
import com.winchain.provider.expiration.cmd.BillExpCertCmd;
import com.winchain.provider.expiration.cmd.BillExpResDctFinQuotaCmd;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class BillExpHandleSubscriber extends OnErrorNotImplementedSubscriber<BillExpirationEvent> {
	@Autowired
	private BillOptCmd<CbRec> billOptCmd;
	@Autowired
	private BillMoveCmd<CbRec> billMoveCmd;
	@Autowired
	private BillExpCertCmd billExpCertCmd;
	@Autowired
	private BillExpResDctFinQuotaCmd billExpResDctFinQuotaCmd;

	public void onApplicationEvent(BillExpirationEvent t) {
		Bill<CbRec> bill = new Bill();
		bill.setRec((CbRec) t.getValue("bill"));
		bill.setSource((CbRec) t.getValue("bill"));
		CommandContext<Bill<CbRec>> context = new CommandContext();
		context.setSource(bill);
		context.setValue("Operation", t.getValue("operation"));
		ChainBase<Bill<CbRec>> crb = new ChainBase();
		crb.add(this.billOptCmd);
		crb.add(this.billMoveCmd);
		crb.add(this.billExpCertCmd);

		crb.add(this.billExpResDctFinQuotaCmd);
		crb.execute(context);
	}
}
